<?php 
include('../../Connections/KRAPPERCON.php');
$oper = $_POST['oper'];
$newnro = $_POST['orden'];
$fecdoc = $_POST['t_fecdoc'];
$fecent = $_POST['t_fecent'];
$codprv = $_POST['cb_proveedor'];
$cladoc = $_POST['cb_oc_cdoc'];
$moneda = $_POST['moneda'];
$provision = $_POST['provision'];
$ref = $_POST['t_oc_ref'];
$items = $_POST['items'];

/*$fecdoc = '2013-02-20';
$fecent = '2013-02-20';
$codprv = '10004';
$cladoc = 'OC_OK';
$items = '178010C010|12.32|3|Filtro de Aire1 #178010C010|10.45|7|Filtro de Aire2#';*/
//echo $oper;
if ($oper == 'add'){
/*
	$sql = "call sp_saveOrden('".$fecdoc."','".$fecent."',".$codprv.",'".$cladoc."','".$items."','".$user_now."','".$ref."');";
	doEcho($sql);
	//exit;
	$res = $mysqli->query($sql) or die($mysqli->error.__LINE__);
	if ($res)
	if ($row = $res->fetch_assoc()){
		$newnro = $row['newnro'];
		if ($newnro > 0) {
			echo '<script type="text/javascript">$("#sp_nroord").html("'.$newnro.'");updItemOC();noEditOC();$(".rowDel").remove();showOk("Se ha creado la Orden '.$newnro.'");
					
				</script>';
		}
		else {
			echo '<script type="text/javascript">showOk("'.$row['msg_err'].'");</script>';
		}
	}
	*/
}
else 
	if ($oper == 'upd'){
		/*
		`sp_saveOrden`(
nro decimal(10,0),fecdoc date, fecent date,codprv numeric(10,0),
cldoc char(5),moned char(5),
items varchar(500), usrid char(15), ref varchar(20))
		*/
	
		$sql = "call sp_saveEKKO('".$newnro."','".$fecdoc."','".$fecent."','".$codprv."','".$cladoc."','".$moneda."','".$items."','".$user_now."','".$ref."','".$provision."');";
		doEcho($sql);
		//exit;
		$res = $mysqli->query($sql) or die($mysqli->error.__LINE__);
		if ($res){
			if ($row = $res->fetch_assoc()){
				$newnro = $row['newnro'];
				if ($newnro > 0) {
					echo '<script type="text/javascript">$("#sp_nroord").html("'.$newnro.'");updItemOC();noEditOC();showOk("Se ha '.$row['tip_msg'].' la Orden '.$newnro.'");
							
						</script>';
				}
				else {
					echo '<script type="text/javascript">showError("Error al Generar la OC\n'.$row['msg_err'].'\n'.$row['pos_doc'].'");</script>';
				}
			}
			$res->close();
				$mysqli->check_result();
			}
	}

?>